package com.wanmait.myhouse.managerController;

import com.wanmait.myhouse.dao.RoomDAO;
import com.wanmait.myhouse.vo.Room;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.awt.*;
import java.util.List;

@Controller
@RequestMapping("manager")
public class ManagerAddRoomController {


    @GetMapping("deleteRoom")
    @ResponseBody
    public String deleteRoom(Room room){
        RoomDAO roomDAO = new RoomDAO();
        roomDAO.deleteById(room);
        return "1";
    }

    @GetMapping("selectBynum")
    @ResponseBody
    public String selectBynum(Room room){
        RoomDAO roomDAO = new RoomDAO();
        Room room1 = roomDAO.findByNum(room);
        if (room1 == null){
            return "1";
        }
            return "0";
    }



    @GetMapping("AddRoom")
    public String AddRoom(Model model,Room room){
        RoomDAO roomDAO = new RoomDAO();
        if(room.getRoomNum()!=null){
            roomDAO.MgAddRoom(room);
        }
        List<Room> roomList = roomDAO.FindAll();
        model.addAttribute("roomList",roomList);
        return "manager/AddRoom";
    }

}
